<!-- 项目档案 -->
<template>
  <div class="container">
    <div class="header">
      <el-form inline class="searchItem">
        <div style="display: flex;">
          <el-form-item label="项目关键字">
              <el-input
                  v-model="code"
                  size="small"
                  placeholder="请输入项目名称/负责人"
                  style="width: 100%;"
                  clearable
              />
          </el-form-item>
          <!-- <el-form-item label="项目名称">
              <el-input
                  v-model="name"
                  size="small"
                  placeholder="请输入项目名称"
                  style="width: 100%;"
              />
          </el-form-item>
          <el-form-item label="项目负责人">
              <el-input
                  v-model="person"
                  size="small"
                  placeholder="请输入项目负责人"
                  style="width: 100%;"
              />
          </el-form-item> -->
        </div>
        <div style="display: flex;">
          <el-form-item>
              <el-button
                  size="small"
                  type="primary"
                  @click="handleSearch" 
                  icon="el-icon-search"
                  >查询</el-button
              >
              <el-button
                  size="small"
                  type="warning"
                  @click="handleReset"
                  icon="el-icon-refresh-left"
                  >重置</el-button
              >
              <el-button
                  size="small"
                  type="primary"
                  @click="addOnClick" 
                  icon="el-icon-plus"
                  >新增</el-button
              >
          </el-form-item>
        </div>
      </el-form>
    </div>
    <div class="main">
      <RlTable
          :search="false"
          :is-pagination="true"
          @on-change="loadTableData"
          ref="rlTable"
      >
          <template #default>
              <el-table-column label="序号" type="index" width="80" fixed="left" />
              <el-table-column prop="name" label="项目名称" />
              <el-table-column prop="projectPerson" label="项目负责人" />
              <el-table-column prop="phone" label="联系电话" />
              <el-table-column prop="createTime" label="创建时间" />
              <el-table-column fixed="right" label="操作" width="140">
                  <template slot-scope="{ row }">
                      <Operation :rowData="row" />
                  </template>
              </el-table-column>
          </template>
      </RlTable>
    </div>
  </div>
</template>

<script>
import Operation from './components/Operation.vue'
import FormModal from './components/FormModal.vue'
import { findProArchivePageList } from '@/api/proArchive'
export default {
  components:{
    Operation,
    FormModal
  },
  data(){
    return {
      code: '',
      name: '',
      person: '',
      list: [
        {
          code: '123',
          name: '123',
          person: '123',
          phone: '123',
          createTime: '123'
        },
      ]
    }
  },
  methods:{
    handleSearch(){
      this.$nextTick(() => {
          const rlTable = this.$refs.rlTable
          if(rlTable){
            rlTable.onSearchChange()
          }
        })
    },
    loadTableData({resolve, params}) {
        // resolve({
            // records:this.list,
            // total:0
        // })
        params.condition = this.code
        // params.desc = ['id']
        findProArchivePageList(params).then(res => {
          if(res.code == '200'){
            const resData = res.data || {}
            resolve({
              records: resData.records || [],
              total: resData.total || 0
            })
          }else{
            resolve({
                records:[],
                total:0
            })
          }
        })
    },
    handleReset(){
      this.code = ''
      this.name = ''
      this.person = ''
      this.handleSearch()
    },
    addOnClick(){
      new this.$pageModal(
          FormModal,
          {
              props: {
                  title: '新增',
              },
          },
          (result) => {
              if (result) {
                const rlTable = this.$refs.rlTable
                if(rlTable){
                  rlTable.onSearchChange()
                }
              }
          }
      )
    }
  }

}
</script>

<style lang="scss" scoped>
.container {
  color: #fff;
  display: flex;
  flex-direction: column;
  width: 100%;
}
.header {
  height: 36px;
  background-color: #0C2E64;
  padding: 20px 15px;
  display: flex;
  .searchItem {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  margin-bottom: 34px;
}
.main {
  height: calc(100vh - 240px);
  position: relative;
  box-sizing: border-box;
}
::v-deep .el-form-item {
  margin-bottom: 0 !important;
  line-height: 36px !important;
  height: 36px !important;
}
::v-deep .el-form-item__label {
  line-height: 36px !important;
  height: 36px!important;
}
::v-deep .el-form-item__content {
  line-height: 36px !important;
  height: 36px !important;
}
</style>